﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace IPC.Communication.LogNet
{
    public class LogNetManagment
    {
        internal const string LogFileHeadString = "Logs_";

        public static ILogNet LogNet
        {
            get;
            set;
        }

        internal static string GetDegreeDescription(HslMessageDegree degree)
        {
            string result;
            switch (degree)
            {
                case HslMessageDegree.None:
                    result = StringResources.Language.LogNetAbandon;
                    break;
                case HslMessageDegree.FATAL:
                    result = StringResources.Language.LogNetFatal;
                    break;
                case HslMessageDegree.ERROR:
                    result = StringResources.Language.LogNetError;
                    break;
                case HslMessageDegree.WARN:
                    result = StringResources.Language.LogNetWarn;
                    break;
                case HslMessageDegree.INFO:
                    result = StringResources.Language.LogNetInfo;
                    break;
                case HslMessageDegree.DEBUG:
                    result = StringResources.Language.LogNetDebug;
                    break;
                default:
                    result = StringResources.Language.LogNetAbandon;
                    break;
            }
            return result;
        }

        public static string GetSaveStringFromException(string text, Exception ex)
        {
            StringBuilder stringBuilder = new StringBuilder(text);
            bool flag = ex != null;
            if (flag)
            {
                bool flag2 = !string.IsNullOrEmpty(text);
                if (flag2)
                {
                    stringBuilder.Append(" : ");
                }
                try
                {
                    stringBuilder.Append(StringResources.Language.ExceptionMessage);
                    stringBuilder.Append(ex.Message);
                    stringBuilder.Append(Environment.NewLine);
                    stringBuilder.Append(StringResources.Language.ExceptionSource);
                    stringBuilder.Append(ex.Source);
                    stringBuilder.Append(Environment.NewLine);
                    stringBuilder.Append(StringResources.Language.ExceptionStackTrace);
                    stringBuilder.Append(ex.StackTrace);
                    stringBuilder.Append(Environment.NewLine);
                    stringBuilder.Append(StringResources.Language.ExceptionType);
                    stringBuilder.Append(ex.GetType().ToString());
                    stringBuilder.Append(Environment.NewLine);
                    stringBuilder.Append(StringResources.Language.ExceptionTargetSite);
                    StringBuilder arg_102_0 = stringBuilder;
                    MethodBase expr_F6 = ex.TargetSite;
                    arg_102_0.Append((expr_F6 != null) ? expr_F6.ToString() : null);
                }
                catch
                {
                }
                stringBuilder.Append(Environment.NewLine);
                stringBuilder.Append("\u0002/=================================================[    Exception    ]================================================/");
            }
            return stringBuilder.ToString();
        }
    }
}
